package com.liuxin.zhiyuan.user.controller;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.system.UserInfo;
import com.liuxin.common.utils.UserContext;
import com.liuxin.zhiyuan.user.domain.dto.LoginFormDTO;
import com.liuxin.zhiyuan.user.domain.po.LxzyRole;
import com.liuxin.zhiyuan.user.domain.po.LxzyUser;
import com.liuxin.zhiyuan.user.domain.vo.UserInfoVO;
import com.liuxin.zhiyuan.user.domain.vo.UserLoginVO;
import com.liuxin.zhiyuan.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.liuxin.zhiyuan.user.service.RoleService;
import com.liuxin.common.utils.PageUtils;
import com.liuxin.common.utils.R;



/**
 * 
 *
 * @author zsl
 * @email 1301966496@qq.com
 * @date 2025-09-17 22:41:08
 */
@RestController
@RequestMapping("/user/users")
@RefreshScope
public class UserController {
    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;


    /**
     * 信息
     */
    @RequestMapping("/info")
    public R info(){
        Long userId = UserContext.getUser();
        if (userId == null) {
            return R.error("请先登录,请先登录");
        }
        UserInfoVO user = userService.queryUserInfo(userId);
        return R.ok().put("data", user);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        Long user = UserContext.getUser();
        PageUtils page = roleService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LxzyRole role){
		roleService.save(role);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LxzyRole role){
		roleService.updateById(role);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		roleService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
